package org.dlsu.mt.parser;

import java.util.StringTokenizer;

public class SemEntry
{
	private String[] target;
	private String attribute;
	private String value;
	
	public SemEntry(String attribute, String value)
	{
		this.attribute = attribute;
		this.value = value;
		target = null;
	}
	
	public SemEntry(String[] target, String attribute, String value)
	{
		this.target = target;
		this.attribute = attribute;
		this.value = value;
	}
	
	public SemEntry(String targetStr, String attribute, String value)
	{
		this.target = parseTarget(targetStr);
		this.attribute = attribute;
		this.value = value;
	}
	
	public String[] parseTarget(String target)
	{
		StringTokenizer temp = new StringTokenizer(target);
		String[] list = new String[temp.countTokens()];
		String token = null;
		int i=0;
		
		while(temp.hasMoreTokens())
		{
			token = temp.nextToken();
			list[i] = token;
		}
		
		if(list.length != 0)
			return list;
		return null;
	}
	
	public String getAttribute()
	{
		return attribute;
	}
	
	public String getValue()
	{
		return value;
	}
	
	public String[] getTarget()
	{
		return target;
	} 
	
	public boolean hasTarget()
	{
		if(target != null)
			return true;
		return false;
	}
	
	public String toString()
	{
		StringBuffer temp = new StringBuffer();
		if(target != null)
		{
			for(int i=0;i<target.length;i++)
			{
				temp.append(target[i] + " ");
			}
		}
		temp.append(attribute + " = ");
		temp.append(value);
		
		return temp.toString();
	}
}